/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package modele;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Collection;
import java.util.HashSet;
import java.util.TreeSet;

/**
 *
 * @author ltata
 */
public class DAO {

    static Collection<Deps> getLesDeps() {
        Collection<Deps> lesColDeDeps = new TreeSet<Deps>();

        try {
            Connection con = Connect.get();
            Statement req;
            req = con.createStatement();
            ResultSet rs = req.executeQuery("SELECT DISTINCT departement FROM medecin");
            while (rs.next()) {
                Deps d = new Deps(rs.getString("departement"));
                lesColDeDeps.add(d);
            }


        } catch (SQLException e) {
            System.out.println("Erreur SQL :" + e);
        }
        return lesColDeDeps;
    }

    static Collection<Med> getLesMeds()  {
        Collection<Med> lesColDeMeds = new TreeSet<Med>();
        try {
        Connection con = Connect.get();
        Statement req;
                req = con.createStatement();
                ResultSet rs = req.executeQuery("SELECT *  FROM medecin");
                while (rs.next()) {
                    Med m = new Med(rs.getString("nom"), rs.getString("prenom"), rs.getString("adresse"), rs.getString("tel"), rs.getString("specialitecomplementaire"), rs.getString("id"), rs.getString("departement"));
                    lesColDeMeds.add(m);
                }
            }
         catch (SQLException e) {
            System.out.println("Erreur SQL :" + e);
        }
        return lesColDeMeds;
    }
    
        static Collection<Specialite> getLesSpes() {
        Collection<Specialite> lesColDeSpes = new TreeSet<Specialite>();
        try {
        Connection con = Connect.get();
        Statement req;
                req = con.createStatement();
                ResultSet rs = req.executeQuery("SELECT DISTINCT specialitecomplementaire FROM medecin WHERE specialitecomplementaire IS NOT null;");
                while (rs.next()) {
                    Specialite s = new Specialite(rs.getString("specialitecomplementaire"));
                    lesColDeSpes.add(s);
                }
            }
         catch (SQLException e) {
            System.out.println("Erreur SQL :" + e);
        }
        return lesColDeSpes;
    }
    
}